package com.arch.dev.client.view;

import com.arch.dev.client.vo.CatagoryVO;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;

public class CatagoryFormView extends Composite {

	@UiField(provided = true)
	FlexTable formTable;

	TextArea descTextBox;

	@UiField
	Button cancelButton;

	public Button getCancelButton() {
		return cancelButton;
	}

	public void setCancelButton(Button cancelButton) {
		this.cancelButton = cancelButton;
	}

	@UiField
	Button saveButton;

	private static CatagoryFormViewUiBinder uiBinder = GWT
			.create(CatagoryFormViewUiBinder.class);

	interface CatagoryFormViewUiBinder extends
			UiBinder<Widget, CatagoryFormView> {
	}

	public CatagoryFormView() {
		init();

		initWidget(uiBinder.createAndBindUi(this));
	}

	private void init() {
		formTable = new FlexTable();

		formTable.setCellSpacing(6);

		descTextBox = new TextArea();

		descTextBox.setVisibleLines(1);
		descTextBox.setWidth("200px");

		formTable.setHTML(1, 0, "Description :");

		formTable.setWidget(1, 1, descTextBox);

	}

	public void saveButtonAddClickHandler(ClickHandler handler){
		saveButton.addClickHandler(handler);
	}
	
	private CatagoryVO ctgVO = null;
	
	public CatagoryVO populateVo() {

		CatagoryVO catagoryVO = new CatagoryVO();
		
		if(ctgVO != null && ctgVO.getId() != null){
			catagoryVO.setId(ctgVO.getId());
		}
		

		catagoryVO.setName(descTextBox.getText());

		
		return catagoryVO;

	}
	
	
	public void populateFields(CatagoryVO catagoryVO) {

		ctgVO = catagoryVO;

		descTextBox.setText(catagoryVO.getName());


	}
	
}
